package com.frxuexi.lib_commom

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.module.AppGlideModule
import com.bumptech.glide.request.RequestOptions

@GlideModule
class GlideUtils:AppGlideModule() {

    companion object{
        @JvmStatic
        fun loadRoundImage(context: Context, url: String, iv:ImageView){
            val options = RequestOptions().transform(CenterCrop(), RoundedCorners(20))
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            Glide.with(context)
                .load(url)
                .error(androidx.core.R.drawable.notification_template_icon_bg)
                .apply(options)
                .into(iv)
        }
        @JvmStatic
        fun loadRoundImage(context: Context,resId:Int,iv:ImageView){
            val options = RequestOptions().transform(CenterCrop(), RoundedCorners(20))
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            Glide.with(context)
                .load(resId)
                .error(androidx.core.R.drawable.notification_template_icon_bg)
                .apply(options)
                .into(iv)
        }

        @JvmStatic
        fun loadImage(context: Context, url: String, iv:ImageView){
            val options = RequestOptions().transform(CenterCrop())
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            Glide.with(context)
                .load(url)
                .error(androidx.core.R.drawable.notification_template_icon_bg)
                .apply(options)
                .into(iv)
        }
    }



}